package com.lancoo.cvas.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lancoo.cvas.entity.StudentRetake;
import com.lancoo.cvas.mapper.StudentRetakeMapper;
import com.lancoo.cvas.pojo.response.score.Retake;
import com.lancoo.cvas.service.StudentRetakeService;
import com.lancoo.cvas.util.BatchInsert;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;


@Service("studentRetakeService")
public class StudentRetakeServiceImpl extends ServiceImpl<StudentRetakeMapper, StudentRetake> implements StudentRetakeService {



    @Resource
    private StudentRetakeMapper studentRetakeMapper;

    @Override
    public void syncStudentRetake(Integer taskId, String schoolId, String term, List<Retake> retakes) {
        List<StudentRetake> studentRetakes = new ArrayList<>();

        for (Retake retake : retakes) {
            studentRetakes.add(retake.toEntity(taskId, schoolId, term));
        }

        Consumer<List<StudentRetake>> studentConsumer = o -> studentRetakeMapper.addBatch(o);
        BatchInsert.batchSplitInsert(studentRetakes, studentConsumer);
    }
}